//
// Created by 下次一定 on 2021/9/15.
//

/*
 * 数字全排列
 * 深度遍历
 * 回溯   恢复现场
 * */

#include<iostream>

using namespace std;

const int N = 10;

int n;
int path[N];
bool st[N];

void dfs(int u) {
    if (u == n) {
        for (int i = 0; i < u; i++)cout << path[i] << " ";
        cout << endl;
        return;
    }

    for (int i = 1; i <= n; i++) {
        if (!st[i]) {
            path[u] = i;
            st[i] = true;
            dfs(u + 1);
            //递归结束 恢复现场
            st[i] = false;
        }
    }
}

int main() {
    cin >> n;
    dfs(0);
    return 0;
}
